package com.kingdee.pda.ui.fast_allot;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

import com.example.basecommon.http.MyObserver;
import com.example.basecommon.http.RxHelper;
import com.example.basecommon.http.rxjava.BaseResponse;
import com.example.basecommon.http.rxjava.HttpUtils;
import com.example.basecommon.utils.ConstantUtil;
import com.example.basecommon.utils.SpeakUtils;
import com.kingdee.pda.Api;
import com.kingdee.pda.R;
import com.kingdee.pda.adapter.FastAllotTaskListAdapter;
import com.kingdee.pda.callback.OnCheckBoxChangeListener;
import com.kingdee.pda.callback.OnEditTextChangeListener;
import com.kingdee.pda.commonmethod.QueryStockPresenter;
import com.kingdee.pda.commonmethod.QueryStockView;
import com.kingdee.pda.entity.FastAllotResponseBean;
import com.kingdee.pda.entity.FastAllotTaskResquestBean;
import com.kingdee.pda.entity.LocationListBean;
import com.kingdee.pda.entity.QtfInOutEntryInfo;
import com.kingdee.pda.entity.Warehouse;
import com.kingdee.pda.entity.WarehouseLocation;
import com.kingdee.pda.ui.activity.BaseTitleActivity;
import com.kingdee.pda.util.CommonUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;


/**
 * 快速调拨操作(任务)
 * Created by dlj
 * DATE 2021/9/27
 * TIME 13:25
 */
public class FastAllotOperateTaskActivity extends BaseTitleActivity implements View.OnKeyListener, View.OnClickListener,
        OnCheckBoxChangeListener, OnEditTextChangeListener, QueryStockView {
    private WarehouseLocation mMoveOutLocation;//移出库位信息
    private WarehouseLocation mMoveInLocation;//移入库位信息
    private QtfInOutEntryInfo mOperateGoods;//商品操作对象
    private int mCanMoveQty = 1;//可移动数量
    private EditText et_outLocationcode;
    private EditText et_skuCode;
    private EditText et_inLocationcode;
    private EditText et_number;
    private TextView tv_warehouseInformation, tv_maxNumber, tv_total;
    private TextView tv_edit, tv_delete, tv_save;
    private TextView tv_detailMsg;
    private TextView tv_barCode, tv_skuCode, tv_skuName, tv_recommed_outLocation, tv_planNumber, tv_invStatusName;
    private Button btn_last, btn_finish;
    private RadioButton rb_1;

    private TabLayout tabLayout;
    private String[] titles = new String[]{"计划调拨明细", "实际调拨明细"};

    private RecyclerView recyclerViewPlan;
    private RecyclerView recyclerViewActul;
    private FastAllotTaskListAdapter adapterPlan;
    private FastAllotTaskListAdapter adapterActul;
    private List<QtfInOutEntryInfo> goodsInfoListPlan = new ArrayList();
    private List<QtfInOutEntryInfo> goodsInfoListActul = new ArrayList();

    private int recommedPosition = 0;
    private FastAllotResponseBean fastAllotResponseBean;
    private boolean isMoveOut;
    private QueryStockPresenter queryStockPresenter;

    public static void actionStart(Context context, FastAllotResponseBean fastAllotResponseBean) {
        Intent intent = new Intent(context, FastAllotOperateTaskActivity.class);
        intent.putExtra("data", fastAllotResponseBean);
        context.startActivity(intent);
    }

    @Override
    protected void onActivityCreate(Bundle savedInstanceState) {
        super.onActivityCreate(savedInstanceState);
        setContentView(R.layout.activity_fast_allot__task_operate);
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle("快速调拨");

        et_outLocationcode = findViewById(R.id.et_outLocationcode);
        et_skuCode = findViewById(R.id.et_skuCode);
        et_inLocationcode = findViewById(R.id.et_inLocationcode);
        et_number = findViewById(R.id.et_number);
        rb_1 = findViewById(R.id.rb_1);
        tv_detailMsg = findViewById(R.id.tv_detailMsg);

        setEditTextScannerEvents(et_outLocationcode, this);
        setEditTextScannerEvents(et_skuCode, this);
        setEditTextScannerEvents(et_inLocationcode, this);
        setEditTextScannerEvents(et_number, this);

        tv_warehouseInformation = findViewById(R.id.tv_warehouseInformation);
        tv_maxNumber = findViewById(R.id.tv_maxNumber);
        tv_total = findViewById(R.id.tv_total);
        tv_edit = findViewById(R.id.tv_edit);
        tv_delete = findViewById(R.id.tv_delete);
        tv_save = findViewById(R.id.tv_save);

        tv_barCode = findViewById(R.id.tv_barCode);
        tv_skuCode = findViewById(R.id.tv_skuCode);
        tv_skuName = findViewById(R.id.tv_skuName);
        tv_recommed_outLocation = findViewById(R.id.tv_recommed_outLocation);
        tv_planNumber = findViewById(R.id.tv_planNumber);
        tv_invStatusName = findViewById(R.id.tv_invStatusName);

        btn_last = findViewById(R.id.btn_last);
        btn_finish = findViewById(R.id.btn_finish);

        tv_edit.setOnClickListener(this);
        tv_delete.setOnClickListener(this);
        tv_save.setOnClickListener(this);
        btn_last.setOnClickListener(this);
        btn_finish.setOnClickListener(this);

        recyclerViewPlan = findViewById(R.id.recyclerViewPlan);
        recyclerViewPlan.setLayoutManager(new LinearLayoutManager(this));
        adapterPlan = new FastAllotTaskListAdapter(this, goodsInfoListPlan, this, this);
        recyclerViewPlan.setAdapter(adapterPlan);

        recyclerViewActul = findViewById(R.id.recyclerViewActul);
        recyclerViewActul.setLayoutManager(new LinearLayoutManager(this));
        adapterActul = new FastAllotTaskListAdapter(this, goodsInfoListActul, this, this);
        recyclerViewActul.setAdapter(adapterActul);

        addMoveCountEditChangeListener();

        rb_1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (!b) {//如果是逐件扫描模式，数量输入框不可输入
                    et_number.setText("1");
                    et_number.setEnabled(false);
                } else {
                    et_number.setEnabled(true);
                    et_number.setText("");
                }
            }
        });

        tabLayout = findViewById(R.id.tabLayout);
        for (int i = 0; i < titles.length; i++) {
            tabLayout.addTab(tabLayout.newTab().setText(titles[i]));
        }
        //切换计划/实际调拨详情
        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                int selectPosition = tab.getPosition();
                if (selectPosition == 0) {
                    tv_detailMsg.setText("计划调拨明细");
                    tv_edit.setVisibility(View.GONE);
                    tv_delete.setVisibility(View.GONE);
                    tv_save.setVisibility(View.GONE);
                    recyclerViewPlan.setVisibility(View.VISIBLE);
                    recyclerViewActul.setVisibility(View.GONE);
                    reflushTvTotol(goodsInfoListPlan);
                } else {
                    tv_detailMsg.setText("实际调拨明细");
                    tv_edit.setVisibility(View.VISIBLE);
                    recyclerViewPlan.setVisibility(View.GONE);
                    recyclerViewActul.setVisibility(View.VISIBLE);
                    reflushTvTotol(goodsInfoListActul);
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        queryStockPresenter = new QueryStockPresenter(this, this);
    }

    @Override
    protected void initData() {
        super.initData();

        fastAllotResponseBean = (FastAllotResponseBean) getIntent().getSerializableExtra("data");
        if (fastAllotResponseBean == null) {
            SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "调拨明细获取失败，请检查", false, false);
            return;
        }
        tv_warehouseInformation.setText(fastAllotResponseBean.getWarehouseoutName() + "->" + fastAllotResponseBean.getWarehouseinName());
        List<QtfInOutEntryInfo> qtfInOutEntryInfoList = fastAllotResponseBean.getQtfInOutEntryInfoList();
        //按库位顺序进行排序
        Collections.sort(qtfInOutEntryInfoList, new Comparator<QtfInOutEntryInfo>() {
            public int compare(QtfInOutEntryInfo e1, QtfInOutEntryInfo e2) {
                int a = e1.getOutlocationNumber().compareTo(e2.getOutlocationNumber());
                return a;
            }
        });
        goodsInfoListPlan.clear();
        goodsInfoListPlan.addAll(qtfInOutEntryInfoList);
        adapterPlan.notifyDataSetChanged();
        reflushTvTotol(goodsInfoListPlan);
        reflushNextSku();
    }

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (!(v instanceof EditText)) {
            return false;
        }
        EditText editText = (EditText) v;
        String input = editText.getText().toString().trim();
        if (TextUtils.isEmpty(input)) return false;
        if ((keyCode == KeyEvent.KEYCODE_SYSRQ || keyCode == KeyEvent.KEYCODE_ENTER) && event.getAction() == KeyEvent.ACTION_UP) {
            switch (v.getId()) {
                case R.id.et_skuCode:
                    String skuSplit = CommonUtil.skuCodeSplit(FastAllotOperateTaskActivity.this, input);
                    if (TextUtils.isEmpty(skuSplit)) {
                        SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "商品条码截取结果为空，请检查输入和截图规则", false, false);
                        return false;
                    }
                    et_skuCode.setText(skuSplit);
                    //如果扫描的是没有推荐过的条码
                    if (mOperateGoods.getItemBarcodeNumber().equals(skuSplit)) {
                        //如果是逐件扫描，扫完条码就应该增加数量 1
                        if (!rb_1.isChecked() && mMoveOutLocation != null && mMoveInLocation != null) {
                            reflushListView(1);
                        } else {
                            CommonUtil.requestFocusAndNoClearText(et_outLocationcode);
                        }
                        return true;
                    }

                    SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "扫描的商品条码不属于该调拨单", false, false);
                    CommonUtil.requestFocusAndClearText(et_skuCode);
                    break;
                case R.id.et_outLocationcode:
                    if (mOperateGoods == null) {
                        SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "请输入商品条码并确认", false, false);
                    } else {
                        queryLocationInfo(input, true);
                    }
                    break;
                case R.id.et_inLocationcode:
                    queryLocationInfo(input, false);
                    break;
                case R.id.et_number:
                    try {
                        if (Integer.parseInt(input) > mCanMoveQty) {
                            et_number.setText(String.valueOf(mCanMoveQty));
                            et_number.setSelection(et_number.getText().length());
                        } else if (checkDataValid()) {
                            //刷新列表
                            reflushListView(Integer.parseInt(input));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "数量输入有误！", false, false);
                    }
                    break;
            }
            return true;
        }
        return false;
    }

    /**
     * 查询库位信息
     *
     * @param locationNum 库位编码
     * @param isMoveOut   是否为移出仓库
     */
    private void queryLocationInfo(String locationNum, final boolean isMoveOut) {
        this.isMoveOut = isMoveOut;
        queryStockPresenter.queryWarehouseLocation(isMoveOut ? fastAllotResponseBean.getWarehouseout() : fastAllotResponseBean.getWarehousein(), locationNum);
    }

    //查询库位库存信息
    private void queryGoodsLocationStock(final WarehouseLocation location) {
        if (mOperateGoods == null) {
            SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "请扫描或输入商品条码并按enter", false, false);
            CommonUtil.requestFocusAndNoClearText(et_skuCode);
            return;
        }
        queryStockPresenter.queryGoodsLocationStock(location, mOperateGoods.getInoutskuid(), location.getLocationId() == 0 ? 1 : 0);
    }

    private void addMoveCountEditChangeListener() {
        et_number.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                int input = CommonUtil.formatStringToInt(et_number.getText().toString().trim());
                if (input > mCanMoveQty) {
                    et_number.setText(String.valueOf(mCanMoveQty));
                    et_number.setSelection(et_number.getText().length());
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_edit:
                tv_edit.setVisibility(View.GONE);
                tv_delete.setVisibility(View.VISIBLE);
                tv_save.setVisibility(View.VISIBLE);
                adapterActul.setShowCheckbox(true);
                break;
            case R.id.tv_delete:
                Iterator<QtfInOutEntryInfo> iterator = goodsInfoListActul.iterator();
                while (iterator.hasNext()) {
                    QtfInOutEntryInfo next = iterator.next();
                    if (next.isChecked()) {
                        iterator.remove();
                    }
                }
                adapterActul.notifyDataSetChanged();
                reflushTvTotol(goodsInfoListActul);
                break;
            case R.id.tv_save:
                tv_edit.setVisibility(View.VISIBLE);
                tv_delete.setVisibility(View.GONE);
                tv_save.setVisibility(View.GONE);
                adapterActul.setShowCheckbox(false);
                break;
            case R.id.btn_last:
                finish();
                break;
            case R.id.btn_finish:
                if (goodsInfoListActul != null && goodsInfoListActul.size() > 0) {
                    for (QtfInOutEntryInfo info : goodsInfoListActul) {
                        if (info.getPlantransferqty() > info.getInouttransferqty()) {
                            SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "不能部分调拨", false, true);
                            return;
                        }
                    }
                    FastAllotTaskResquestBean fastAllotTaskResquestBean = new FastAllotTaskResquestBean();
                    fastAllotTaskResquestBean.setId(fastAllotResponseBean.getId());
                    fastAllotTaskResquestBean.setActualTransferDetailsInfos(goodsInfoListActul);

                    MyObserver<BaseResponse> myObserver = new MyObserver<BaseResponse>(this) {
                        @Override
                        public void onSuccess(BaseResponse<BaseResponse> result) {
                            if (result.data.success) {
                                SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "调拨成功", false, true);
                                finish();
                            } else {
                                SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, result.data.message, false, false);
                            }
                        }

                        @Override
                        public void onFailure(BaseResponse result, String msg) {
                            SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, msg, false, false);
                        }
                    };
                    HttpUtils.request(Api.class)
                            .fastallotTaskCommit(ConstantUtil.FASTALLOT_DETAIL_ADD, fastAllotTaskResquestBean)
                            .compose(RxHelper.observableIO2Main(this))
                            .subscribe(myObserver);
                }
                break;
        }
    }

    /**
     * 刷新下方实际调拨明细列表
     *
     * @param qty
     */
    private void reflushListView(int qty) {
        //此sku设置为已推荐
        mOperateGoods.setHasRecommend(true);
        int isExit = -1;//-1 条码还没调拨过  0 调拨过且还能继续调拨  1调拨过且继续调拨后实际数量等于计划数量
        a:
        for (QtfInOutEntryInfo bean : goodsInfoListActul) {
            if (bean.getInlocationid() == mMoveInLocation.getLocationId() && bean.getOutlocationid() == mMoveOutLocation.getLocationId()
                    && bean.getInoutskuid() == mOperateGoods.getInoutskuid() && bean.getInvStatusId() == mOperateGoods.getInvStatusId()) {
                if ((bean.getInouttransferqty() + qty) > mOperateGoods.getInouttransferqty()) {
                    SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "调拨数量超出", false, false);
                    CommonUtil.requestFocusAndNoClearText(et_number);
                    return;
                } else if ((bean.getInouttransferqty() + qty) == mOperateGoods.getInouttransferqty()) {
                    isExit = 1;
                } else if ((bean.getInouttransferqty() + qty) < mOperateGoods.getInouttransferqty()) {
                    isExit = 0;
                }
                bean.setInouttransferqty(bean.getInouttransferqty() + qty);
            }
        }

        if (isExit == -1) {//如果实际明细中未重复则需添加一条实际明细
            try {
                if (qty > mOperateGoods.getInouttransferqty()) {
                    SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "调拨数量超出", false, false);
                    CommonUtil.requestFocusAndNoClearText(et_number);
                    return;
                } else if (qty == mOperateGoods.getInouttransferqty()) {
                    isExit = 1;
                } else if (qty < mOperateGoods.getInouttransferqty()) {
                    isExit = 0;
                }
                QtfInOutEntryInfo addBean = mOperateGoods.clone();
                addBean.setInouttransferqty(qty);
                addBean.setOutlocationid(mMoveOutLocation.getLocationId());
                addBean.setOutlocationNumber(mMoveOutLocation.getLocationCode());
                addBean.setInlocationid(mMoveInLocation.getLocationId());
                addBean.setInlocationNumber(mMoveInLocation.getLocationCode());
                addBean.setInvStatusId(mOperateGoods.getInvStatusId());
                addBean.setInvStatusName(mOperateGoods.getInvStatusName());
                addBean.setPlantransferqty(mOperateGoods.getInouttransferqty());
                goodsInfoListActul.add(0, addBean);
            } catch (CloneNotSupportedException e) {
                e.printStackTrace();
            }
        }

        btn_finish.setEnabled(true);
        adapterActul.notifyDataSetChanged();
//        if (rb_1.isChecked()) {//批量模式下，扫描完成后应该清空界面，并且刷新下一个推荐
        if (isExit == 1) {//如果此项调拨数量已到计划的数量
            et_outLocationcode.setText("");
            mMoveOutLocation = null;
            mMoveInLocation = null;
            reflushNextSku();
        }
        CommonUtil.requestFocusAndClearText(et_skuCode);
        if (tabLayout.getSelectedTabPosition() == 1) {
            reflushTvTotol(goodsInfoListActul);
        }
    }

    /**
     * 刷新推荐文本
     *
     * @param qtfInOutEntryInfo
     */
    private void reflushRecommend(QtfInOutEntryInfo qtfInOutEntryInfo) {
        tv_barCode.setText("商品条码：" + (qtfInOutEntryInfo == null ? "" : qtfInOutEntryInfo.getItemBarcodeNumber()));
        tv_skuCode.setText("商品编码：" + (qtfInOutEntryInfo == null ? "" : qtfInOutEntryInfo.getItemskucode()));
        tv_skuName.setText("规格名称：" + (qtfInOutEntryInfo == null ? "" : qtfInOutEntryInfo.getItemskuname()));
        tv_invStatusName.setText("库存状态：" + (qtfInOutEntryInfo == null ? "" : qtfInOutEntryInfo.getInvStatusName()));
        tv_recommed_outLocation.setText("推荐调出库位：" + (qtfInOutEntryInfo == null ? "" : qtfInOutEntryInfo.getOutlocationNumber()));
        et_inLocationcode.setText(qtfInOutEntryInfo == null ? "" : qtfInOutEntryInfo.getInlocationNumber());
        tv_planNumber.setText("计划调拨数量：" + (qtfInOutEntryInfo == null ? "" : (qtfInOutEntryInfo.getInouttransferqty() + "")));
        tv_maxNumber.setText("");
        if (rb_1.isChecked()) et_number.setText("");
    }

    /**
     * 刷新统计的TextView
     */
    private void reflushTvTotol(List<QtfInOutEntryInfo> list) {
        Set<String> goodType = new HashSet<>();//记录商品种类
        int allQty = 0;//记录调拨总数量
        for (QtfInOutEntryInfo bean : list) {
            goodType.add(bean.getInoutskuid() + "");
            allQty += bean.getInouttransferqty();
        }
        tv_total.setText("商品种类数：" + goodType.size() + "   调拨总数：" + allQty);
    }

    /**
     * 判断下一个推荐的sku、库位应该是哪个
     */
    private void reflushNextSku() {
        if (recommedPosition < goodsInfoListPlan.size()) {
            mOperateGoods = goodsInfoListPlan.get(recommedPosition);
            if (!mOperateGoods.isHasRecommend()) {//没有推荐并操作过刷新推荐，推荐过的话推荐下一个
                reflushRecommend(mOperateGoods);
                recommedPosition++;
            } else {
                recommedPosition++;
                reflushNextSku();
            }
        } else {
            //全部推荐完则清空界面
            reflushRecommend(null);

            mOperateGoods = null;
            et_outLocationcode.setText("");
            et_inLocationcode.setText("");
            et_number.setText("");
        }
    }

    @Override
    public void changeWarehouse(Warehouse warehouse) {
    }

    private void calculateCanMoveQty() {
        if (mMoveOutLocation == null || mMoveInLocation == null || mOperateGoods == null) {
            return;
        }
        //可移入量 = 库位的库容 - 库位库存数 - 该库位待移入数量
        int canMoveInQty = mMoveInLocation.getCanMoveInQty();
        if (canMoveInQty <= 0) {
            tv_maxNumber.setText("* 移入库位没有可用库容量！");
        } else {
            //模拟mMoveOutLocation选中的库存状态（根据计划单中的库存状态）
            for (LocationListBean bean : mMoveOutLocation.getList()) {
                if (mOperateGoods.getInvStatusId() == bean.getInvStatusId()) {
                    mMoveOutLocation.setSelectedStatusBean(bean);
                }
            }
            //可移出数量
            int canMoveOutQty = mMoveOutLocation.getCanMoveOutQty();
            mCanMoveQty = canMoveInQty > canMoveOutQty ? canMoveOutQty : canMoveInQty;
            if (mCanMoveQty == Integer.MAX_VALUE) {
                tv_maxNumber.setText("* 最大可调拨量：无限制");
            } else {
                tv_maxNumber.setText("* 最大可调拨量：" + mCanMoveQty);
            }
        }
    }

    private boolean checkDataValid() {
        if (mOperateGoods == null) {
            SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "商品信息获取失败", false, false);
            CommonUtil.requestFocusAndNoClearText(et_skuCode);
            return false;
        }
        if (mMoveOutLocation == null) {
            SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "调出库位信息获取失败", false, false);
            CommonUtil.requestFocusAndNoClearText(et_outLocationcode);

            return false;
        }
        if (mMoveInLocation == null) {
            SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "调入库位信息获取失败", false, false);
            CommonUtil.requestFocusAndNoClearText(et_inLocationcode);
            return false;
        }
        if (mCanMoveQty == 0) {
            SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "商品可移库数量为0", false, false);
            return false;
        }
        int moveQty = CommonUtil.formatStringToInt(et_number.getText().toString().trim());
        if (moveQty == 0) {
            SpeakUtils.speakWithToast(FastAllotOperateTaskActivity.this, "请输入移库数量", false, false);
            CommonUtil.requestFocusAndNoClearText(et_number);
            return false;
        }
        return true;
    }

    @Override
    public void onCheckChanged(int position, boolean isChecked) {
        //处理删除按钮的亮起
        goodsInfoListActul.get(position).setChecked(isChecked);
        boolean hasChecked = false;
        a:
        for (QtfInOutEntryInfo bean : goodsInfoListActul) {
            if (bean.isChecked()) {
                hasChecked = true;
                break a;
            }
        }

        if (hasChecked) {
            tv_delete.setTextColor(getResources().getColor(R.color.color_4f7eff));
        } else {
            tv_delete.setTextColor(getResources().getColor(R.color.color_999999));
        }
    }

    @Override
    public void onEditTextChanged(int position, int num) {
        goodsInfoListActul.get(position).setInouttransferqty(num);

        reflushTvTotol(goodsInfoListActul);
    }

    @Override
    public void queryWarehouseLocationSuccess(WarehouseLocation warehouseLocation) {
        if (isMoveOut) {
            mMoveOutLocation = warehouseLocation;
            mMoveOutLocation.setWarehouseId(fastAllotResponseBean.getWarehouseout());
            queryGoodsLocationStock(mMoveOutLocation);
        } else {
            mMoveInLocation = warehouseLocation;
            mMoveInLocation.setWarehouseId(fastAllotResponseBean.getWarehousein());
            queryGoodsLocationStock(mMoveInLocation);
        }
    }

    @Override
    public void queryWarehouseLocationFailed(String message) {
        SpeakUtils.speakWithToast(this, message, false, false);
        if (isMoveOut) {
            mMoveOutLocation = null;
            CommonUtil.requestFocusAndClearText(et_outLocationcode);
        } else {
            mMoveInLocation = null;
            CommonUtil.requestFocusAndClearText(et_inLocationcode);
        }
    }

    @Override
    public void queryGoodsLocationStockSuccess(WarehouseLocation warehouseLocation) {
        if (!isMoveOut) {
            mMoveInLocation = warehouseLocation;
            calculateCanMoveQty();
            //如果是逐件扫描，扫完移入库位就应该增加数量 1
            if (!rb_1.isChecked() && checkDataValid()) {
                reflushListView(1);
            } else {
                CommonUtil.requestFocusAndNoClearText(et_number);
            }
        } else {
            mMoveOutLocation = warehouseLocation;
            for (LocationListBean bean : mMoveOutLocation.getList()) {
                if (mOperateGoods != null && bean.getInvStatusId() == mOperateGoods.getInvStatusId()) {
                    mMoveOutLocation.setSelectedStatusBean(bean);
                }
            }
            //因为移入库位是默认填入的，所以扫描移出库位时，应当立即查询移入库位信息
            if (!TextUtils.isEmpty(et_inLocationcode.getText().toString())) {
                queryLocationInfo(et_inLocationcode.getText().toString(), false);
            } else {
                CommonUtil.requestFocusAndNoClearText(et_inLocationcode);
            }
        }
    }

    @Override
    public void queryGoodsLocationStockFailed(String message) {
        SpeakUtils.speakWithToast(this, message, false, false);

    }
}
